package org.yagnus.stats.sampler.discrete.withreplacement;

import java.util.ArrayList;
import java.util.List;

import org.yagnus.stats.sampler.discrete.ArraySampler;

/**
 * 
 * @author hc.busy
 * 
 * @param <T>
 */
abstract public class WithReplacementSampler<T> extends ArraySampler<T> {

    /**
     * 
     * draws a random sample
     * 
     * @return the item drawn
     * 
     */
    abstract public T draw();

    /**
     * This mehod is a default implementation of drawing a bunch of things derived sub-classes
     * should implement more efficient version if they're available
     * 
     * @param n
     * @return
     */
    public List<T> draw(int n) {
        List<T> ret = new ArrayList<T>(n);
        for (int i = 0; i < n; ++i) {
            ret.add(draw());
        }
        return ret;
    }

    public WithReplacementSampler(T[] t) {
        super(t);
    }

    public WithReplacementSampler(T[] t, int[] weights) {
        super(t, weights);
    }

    public WithReplacementSampler(T[] t, long[] weights) {
        super(t, weights);
    }

    public WithReplacementSampler(T[] t, double[] weights) {
        super(t, weights);
    }
}
